package com.jsoft.service;

import com.jsoft.dto.MenuItemDto;
import com.jsoft.manager.MenuItemManager;
import com.jsoft.model.MenuGroupDao;
import com.jsoft.manager.MenuGroupManager;
import com.jsoft.model.MenuItemDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * Date: 28.09.13
 * Time: 10:00
 */

@Service
public class MenuItemServiceImpl implements MenuItemService {
    @Autowired
    private MenuItemManager menuItemManager;
    @Autowired
    private MenuGroupManager menuGroupManager;

    @Override
    @Transactional(readOnly = true)
    public List<MenuItemDto> getMenuItemList(Integer menuId, Integer menuGroupId) {
        MenuGroupDao menuGroup = menuGroupManager.getByMenuIdAndMenuGroupId(menuId, menuGroupId);
        List<MenuItemDao> menuItemList = menuGroup.getMenuItems();
        List<MenuItemDto> result = new ArrayList<MenuItemDto>();
        for (MenuItemDao dao : menuItemList) {
            result.add(dao.wrapMenuItemDto());
        }
        return result;
    }
}
